#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import types

usermodes = ['@','+','%','&','~','!']

class Chan:
    def __init__(self,name):
        self.name = name
        self.users = []
        self.oper = []
        self.voice = []
        self.half = []
        self.topic = ""
        self.modes = []
        self.bans = []
        self.exceptions = []
        
    def __str__(self):
        return self.name
    
    def __repr__(self):
        return self.name
    
    def __eq__(self,other):
        a = self.name
        if self.__class__ == other.__class__:
            b = other.name
        elif type(other) == types.StringType:
            b = other
        else:
            return False
        return a == b
        
    def __ne__(self,other):
        return not self.__eq__(other)
    
    def getUsers(self):
        list = []
        for u in self.users:
            list.append(u['nick'])
        return list
    
    def changeUserNick(self,oldnick,newnick):
        for u in self.users:
            if u['nick'] == oldnick:
                u['nick'].nick = newnick
    
    def addUser(self,nick,mode):
        self.delUser(User(nick))
        self.users.append({'nick':nick,'mode':mode})
        
    def delUser(self,nick):
        for u in self.users:
            if u['nick'] == nick:
                self.users.remove(u)
    
    def getOps(self,chan):
        list = []
        for u in self.users:
            if u['mode'] == "@":
                list.append(u['nick'])
        return list
    
class User:
    def __init__(self,nick,host="",user=""):
        self.nick = nick
        self.user = ""
        self.host = ""
        
    def __str__(self):
        return self.nick
    
    def __repr__(self):
        return self.nick
    
    def __eq__(self,other):
        a = self.nick
        if self.__class__ == other.__class__:
            b = other.nick
        elif type(other) == types.StringType:
            b = other
        else:
            return False
        return a == b
        
    def __ne__(self,other):
        return not self.__eq__(other)
    
    def isClone(self,other):
        return self.host == other.host